package com.hjm.project.agentInfo.AgentCountData.controller;

import java.util.HashMap;
import java.util.List;

import com.hjm.project.agentInfo.AgentCountData.domain.AgentCountData;
import com.hjm.project.agentInfo.AgentCountData.service.AgentCountDataService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.framework.web.page.TableDataInfo;
import com.hjm.common.utils.poi.ExcelUtil;

import javax.annotation.Resource;

/**
 * 代理商交易额统计Controller
 * 
 * @author maker-platform
 * @date 2021-03-05
 */
@Controller
@RequestMapping("/AgentAmount/agentAmount")
public class AgentCountDataController extends BaseController
{
    private String prefix = "agentInfo/AgentCountData";

    @Resource
    private AgentCountDataService agentTransactionAmountService;

    @RequiresPermissions("AgentAmount:agentAmount:view")
    @GetMapping()
    public String agentAmount()
    {
        return prefix + "/agentAmount";
    }

    /**
     * 查询代理商交易额统计列表
     */
    @RequiresPermissions("AgentAmount:agentAmount:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AgentCountData agentTransactionAmount) {
        AgentCountData agentCountData = agentTransactionAmountService.selectMoneySum(agentTransactionAmount);
        HashMap data = new HashMap();
        data.put("sumMoney", agentCountData.getAmount() == null ? "0" :agentCountData.getAmount());
        startPage();
        List<AgentCountData> list = agentTransactionAmountService.selectAgentTransactionAmountList(agentTransactionAmount);
        return getDataTable(list,data);
    }

    /**
     * 导出代理商交易额统计列表
     */
    @RequiresPermissions("AgentAmount:agentAmount:export")
    @Log(title = "代理商交易额统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AgentCountData agentTransactionAmount)
    {
        List<AgentCountData> list = agentTransactionAmountService.selectAgentTransactionAmountList(agentTransactionAmount);
        ExcelUtil<AgentCountData> util = new ExcelUtil<AgentCountData>(AgentCountData.class);
        return util.exportExcel(list, "agentAmount");
    }

    /**
     * 新增代理商交易额统计
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存代理商交易额统计
     */
    @RequiresPermissions("AgentAmount:agentAmount:add")
    @Log(title = "代理商交易额统计", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AgentCountData agentTransactionAmount)
    {
        return toAjax(agentTransactionAmountService.insertAgentTransactionAmount(agentTransactionAmount));
    }

    /**
     * 修改代理商交易额统计
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        AgentCountData agentTransactionAmount = agentTransactionAmountService.selectAgentTransactionAmountById(id);
        mmap.put("agentTransactionAmount", agentTransactionAmount);
        return prefix + "/edit";
    }

    /**
     * 修改保存代理商交易额统计
     */
    @RequiresPermissions("AgentAmount:agentAmount:edit")
    @Log(title = "代理商交易额统计", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AgentCountData agentTransactionAmount)
    {
        return toAjax(agentTransactionAmountService.updateAgentTransactionAmount(agentTransactionAmount));
    }

    /**
     * 删除代理商交易额统计
     */
    @RequiresPermissions("AgentAmount:agentAmount:remove")
    @Log(title = "代理商交易额统计", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(agentTransactionAmountService.deleteAgentTransactionAmountByIds(ids));
    }
}
